package cn.school.localization.service.impl;

import cn.school.localization.dao.StudentPositionDao;
import cn.school.localization.entity.StudentPositionDo;
import cn.school.localization.service.StudentPositionService;
import cn.school.localization.vo.PositionInfoVo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * @className: StudentPositionServiceImpl
 * @author: Alex
 * @date: 2023/3/25
 **/
@Service
public class StudentPositionServiceImpl implements StudentPositionService {
	@Autowired
	private StudentPositionDao studentPositionDao;
	
	@Override
	public int addPosition(PositionInfoVo vo) {
		StudentPositionDo studentPositionDo = new StudentPositionDo();
		BeanUtils.copyProperties(vo, studentPositionDo);
		
		return studentPositionDao.insert(studentPositionDo);
	}
	
	@Override
	public List<StudentPositionDo> getRunningTrace(PositionInfoVo vo) {
		LambdaQueryWrapper<StudentPositionDo> lambdaQueryWrapper = new LambdaQueryWrapper<>();
		lambdaQueryWrapper.eq(StudentPositionDo::getStudentId, vo.getStudentId());
		lambdaQueryWrapper.ge(Objects.nonNull(vo.getCreateTime()), StudentPositionDo::getCreateTime, vo.getCreateTime());
		lambdaQueryWrapper.le(Objects.nonNull(vo.getModifyTime()), StudentPositionDo::getCreateTime, vo.getModifyTime());
		
		return studentPositionDao.selectList(lambdaQueryWrapper);
	}
}
